﻿using System.Diagnostics;

namespace Quail
{
    /// <summary>
    /// Implements a simple stopwatch using the default browser timeouts
    /// </summary>
    public class TestStopwatch
    {
        private readonly int _ms;
        private readonly Stopwatch _sw;

        /// <summary>
        /// Initializes a new instance of the WebBrowserStopwatch class.
        /// </summary>
        /// <param name="ms">The number of milliseconds for the stopwatch until Expired is set to True</param>
        public TestStopwatch(int ms)
        {
            _sw = new Stopwatch();
            _ms = ms;
            _sw.Start();
        }

        /// <summary>
        /// Gets a value indicating whether the timeout has elapsed
        /// </summary>
        public bool Expired
        {
            get
            {
                return _sw.ElapsedMilliseconds > _ms;
            }
        }

        /// <summary>
        /// Gets the timeout of the stopwatch
        /// </summary>
        public int Timeout
        {
            get
            {
                return _ms;
            }
        }

        /// <summary>
        /// Restarts the stopwatch
        /// </summary>
        public void Restart()
        {
            _sw.Reset();
            _sw.Start();
        }
    }
}
